<template>
  <div>
    <div class="all-data">
      <div class="title">实时数据</div>
      <div class="flex-list">
        <div v-show="temp&&temp.val">
          <div class="item"
               style="backgroundColor:#FFE897">
            <div>
              <div>
                <span class="num">{{temp&&temp.val?temp.val.toFixed(1):'NC'}}</span>
                <span>℃</span>
              </div>
              <div>温度</div>
            </div>
            <div class="img">
              <img src="@/assets/platformDetail/opt/icon_temp_new.png" />
            </div>
          </div>
        </div>
        <div v-show="water&&water.val">
          <div class="item"
               style="backgroundColor:#B3E2FF">
            <div>
              <div>
                <span class="num">{{water&&water.val?water.val:'NC'}}</span>
                <span>%</span>
              </div>
              <div>湿度</div>
            </div>
            <div class="img">
              <img src="@/assets/platformDetail/opt/icon_water_new.png" />
            </div>
          </div>
        </div>
        <div>
          <div class="item"
               style="backgroundColor:rgba(255, 244, 242, 1)">
            <div>
              <div>
                <span class="num">{{cor_opt_lux&&cor_opt_lux.val?cor_opt_lux.val.toFixed(1):'NC'}}</span>
                <span>lx</span>
              </div>
              <div>照度</div>
            </div>
            <div class="img">
              <img src="@/assets/platformDetail/opt/icon_lx_new.png" />
            </div>
          </div>
        </div>
        <div>
          <div class="item"
               style="backgroundColor:#FFFBEE">
            <div>
              <div>
                <span class="num">{{cct&&cct.val?cct.val.toFixed(0):'NC'}}</span>
                <span>k</span>
              </div>
              <div>色温</div>
            </div>
            <div class="img">
              <img src="@/assets/platformDetail/opt/icon_k_new.png" />
            </div>
          </div>
        </div>
        <div>
          <div class="item"
               style="backgroundColor:#EFF8FF">
            <div>
              <div>
                <span class="num">{{eml&&eml.val?eml.val.toFixed(1):'NC'}}</span>
              </div>
              <div>EML</div>
            </div>

            <div class="img">
              <img src="@/assets/platformDetail/opt/icon_eml_new.png" />
            </div>

          </div>
        </div>
        <div>
          <div class="item"
               style="backgroundColor:#F3F1FF">
            <div>
              <div>
                <span class="num">{{edi&&edi.val?edi.val.toFixed(1):'NC'}}</span>
                <span>lx</span>
              </div>
              <div>EDI</div>
            </div>
            <div class="img">
              <img src="@/assets/platformDetail/opt/icon_edi_new.png" />
            </div>

          </div>
        </div>
        <div>
          <div class="item"
               style="backgroundColor:#F3FFF6">

            <div>
              <div>
                <span class="num">{{cla&&cla.val?cla.val.toFixed(1):'NC'}}</span>
              </div>
              <div>CL<sub>A</sub></div>
            </div>
            <div class="img">
              <img src="@/assets/platformDetail/opt/icon_ra_new.png" />
            </div>
          </div>
        </div>

        <div>
          <div class="item"
               style="backgroundColor:#F8F8F8">
            <div>
              <div>
                <span class="num">{{cs&&cs.val?cs.val.toFixed(3):'NC'}}</span>
              </div>
              <div>CS</div>
            </div>

            <div class="img">
              <img src="@/assets/platformDetail/opt/icon_cs_new.png" />
            </div>
          </div>
        </div>

      </div>
    </div>
  </div>
</template>
<script>
import { getAllDeviceDataRealtime } from "@/api/platformManage";
export default {
  name: "overView",
  props: {
    deviceId: {
      type: String,
      default: ""
    },
    deviceName: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      eml: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      edi: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      cs: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      cla: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      //照度
      opt_lux: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      //照度
      cor_opt_lux: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      //色温
      cct: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      //温度
      temp: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      //湿度
      water: {
        val: 0,
        evaluate: {
          healthLevelShow: 0
        }
      },
      timer: null
    };
  },
  filters: {
  },
  watch: {

  },
  mounted() {
    this.getAllDeviceDataRealtimeFun(this.deviceId);
    this.timer = setInterval(() => {
      this.getAllDeviceDataRealtimeFun(this.deviceId);
    }, 30000);
  },
  unmounted() {
    clearInterval(this.timer);
  },
  methods: {
    getAllDeviceDataRealtimeFun(deviceId) {
      getAllDeviceDataRealtime(this.deviceId).then(res => {
        let data = res.value;
        if (JSON.stringify(data) == "{}") {
          this.cct = null;
          this.opt_lux = null;
          this.cor_opt_lux = null;
          this.cla = null;
          this.eml = null;
          this.edi = null;
          this.cs = null;
          this.temp = null;
          this.water = null;
        } else {
          this.cct = data.CCT;
          this.opt_lux = data.OPT_LUX;
          this.cor_opt_lux = data.COR_OPT_LUX;
          this.cla = data.CLA;
          this.eml = data.EML;
          this.edi = data.EDI;
          this.cs = data.CS;
          this.temp = data.OPT_TEMPERATURE;
          this.water = data.OPT_HUMILITY;
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.all-data {
  width: 100%;
  background-color: #fff;
  // height: 320px;
  border-radius: 12px;
  .title {
    font-size: 16px;
    font-weight: bold;
    line-height: 21px;
    color: #0a0a0a;
  }
  .flex-list {
    display: flex;
    flex-wrap: wrap;
  }
  .item {
    height: 100px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: row;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bolder;
    font-weight: 400;
    min-width: 180px;
    line-height: 25px;
    // color: #6c6c6c;
    margin: 12px 5px 0 5px;
    padding: 10px;
    .img {
      height: 45px;
      display: flex;
      align-items: center;
      vertical-align: middle;
    }

    .num {
      font-size: 28px;
      font-family: DIN;
      font-weight: bold;
      line-height: 34px;
      color: #242424;
    }
  }
  .level-a {
    color: #0fc821;
  }
  .level-b {
    color: #0681ed;
  }
  .level-c {
    color: #5bb2ff;
  }
  .level-d {
    color: #ff512d;
  }
  .level-e {
    color: #ff0033;
  }
  .level-f {
    color: #ad0808;
  }
  .level-yellow {
    color: #ffc72d;
  }
}
@media screen and (max-width: 1670px) {
  .all-data {
    padding: 20px;
    .num {
      font-size: 28px;
      font-family: DIN;
      font-weight: bold;
      line-height: 34px;
      color: #242424;
    }
  }
}
@media screen and (max-width: 1440px) {
  .all-data {
    width: 100%;
    background-color: #fff;
    // height: 320px;
    border-radius: 12px;
    padding: 10px 30px;
    .title {
      font-size: 16px;
      font-weight: bold;
      line-height: 21px;
      color: #0a0a0a;
    }
    .item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      flex-direction: row;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: bolder;
      line-height: 25px;
      margin: 12px 5px 0 5px;
      min-width: 180px;
      // color: #6c6c6c;
      .img {
        height: 45px;
        display: flex;
        align-items: center;
        vertical-align: middle;
      }

      .num {
        font-size: 20px;
        font-family: DIN;
        font-weight: bold;
        line-height: 34px;
        color: #242424;
      }
    }
  }
}
</style>
